package com.levi.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author shentong
 * @since 2022/1/16 5:24 PM
 * thenAccepeBoth用于将两个异步任务的结果进行合并，该方法没有返回值
 */
public class ThenAcceptBothDemo {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        CompletableFuture<String> future1 = CompletableFuture.supplyAsync(() -> "hello", executorService);

        CompletableFuture<String> future2 = CompletableFuture.supplyAsync(() -> "world", executorService);

        CompletableFuture<Void> future3 = future1.thenAcceptBothAsync(future2, (f1,f2)->{
            System.out.println(f1+f2);
        },executorService);
//        try {
//            System.out.println("执行结果是：>>"+future3.get());
//        } catch (InterruptedException | ExecutionException e) {
//            e.printStackTrace();
//        }
        executorService.shutdown();
    }
}
